<?php namespace App\Models\Cxhshop;

use App\Models\Base\CxhshopBase;

class UserLog extends CxhshopBase {
    protected $table = 'ims_cxh_user_log';

    /**
     * @param $id 车辆补贴id
     * @param $type  1 会员礼包升级  2 代理商升级 3会员关系变化 4车辆补贴相关 5运营补贴相关'
     * @return array
     * 获取当前车辆补贴的所有停发记录
     */
    public function getStopArr($memId,$id,$type){
        $list = self::query()
            ->where('bus_id',$id)
            ->where('member_id',$memId)
            ->where('bus_type',$type)
            ->orderBy('ctime','desc')
            ->get(['id','bus_id','remark','operator_id','on_id','ctime']);
        if($list){
            $allRecords = $list -> toArray();
            $offArr = [];
            foreach ($allRecords as $key=>$val){
                $remarkArr = explode(",",$val['remark']);
                $type = substr($remarkArr[0],6,1);
                if($type == "6"){
                    $offArr[] = $val;
                }
            }
        }else{
            $offArr = [];
        }
        return $offArr;
    }
    /**
     * 获取停发原因
     */
    public function getStopReason($remark){
        //停发原因
        $remarkArr = explode(",", $remark);//remark的内容
        $remarkArr1 = substr($remarkArr[0], 16);
        $remarkArr2 = substr($remarkArr1, 0, strpos($remarkArr1, "'"));
        return $remarkArr2;
    }

    /**
     * 获取续发记录
     * @param $onId  续发记录id
     */
    public function getOnInfo($onId){
        $list = self::query() -> where('id',$onId) -> first();
        if($list){
            $data = $list -> toArray();
        }else{
            $data = [];
        }
        return $data;
}

}